package part3.c16_singleton;

import part3.c16_singleton.Monostate;

/**
 *  先从测试用例考虑
 */
public class MonoStateTest {
    public static void main(String[] args){
        test1();
        test2();
    }

    //一个实例验证
    private static void test1() {
        Monostate m = new Monostate();
        for (int i = 0; i < 10; i++) {
            m.setX(i);
            assert i == m.getX();
        }
    }

    //看起来是不同对象，共享一个变量，不知情的会以为是单例
    //像是拥有不同名字的相同实例
    private static void test2() {
        Monostate m1 = new Monostate();
        Monostate m2 = new Monostate();
        for (int i = 0; i < 10; i++) {
            m1.setX(i);
            assert i == m2.getX();
        }
    }


}
